home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 201-225 / 214 / smarticon / src / hook.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  3KB  |  100 lines

  1. /***************************************************************************/
  2. /*                                       */
  3. /* SmartIcon, release 1.0 - An Intuition object iconifier for the Amiga    */
  4. /* Copyright (c) 1988 Gauthier H. Groult                                   */
  5. /*                                       */
  6. /* Written in January 1988 by Gauthier H. Groult               */
  7. /*                  33, Boulevard Saint Denis,           */
  8. /*                  92400 Courbevoie                   */
  9. /*                  France - Europe                   */
  10. /*                  Tel: (16) 1 47 89 09 54                      */
  11. /*                  email: mcvax!inria!litp!germinal!groult       */
  12. /*                                       */
  13. /* This source code is not in public domain, please do not distribute.       */
  14. /* The binary program is shareaware. Read docs files for details.       */
  15. /*                                       */
  16. /***************************************************************************/
  17.  
  18. #include <exec/types.h>
  19.  
  20. typedef  LONG    (*PFL)();
  21.  
  22. extern     struct   ExecBase     *SysBase;
  23. extern     struct   IntuitionBase  *IntuitionBase;
  24.  
  25. extern     LONG  OWentry_point(), CWentry_point(), MIentry_point(),
  26.            PMentry_point();
  27. extern     VOID  MyOpenWindow(), MyCloseWindow(), MyPutMsg();
  28.  
  29. /* The SetHooks() and CleanHooks() functions set the parameters for     */
  30. /* the SetFunction() calls and execute those. By doing so, the          */
  31. /* libraries (namely Exec and Intuition) vector tables are patched so   */
  32. /* that calls to the specified functions go trough our code before or    */
  33. /* after doing their normal stuff.                    */
  34. /* We must save the old pointers to restore them when exiting.        */
  35. /*                                    */
  36. /* This is derived from DropShadow's hooks.                             */
  37.  
  38. VOID     SetHooks(), CleanHooks();
  39.  
  40. struct     hook
  41.    {
  42.    LONG  hk_SysFunc;
  43.    PFL     hk_MyFunc;
  44.    PFL     hk_Entry;
  45.    LONG  hk_LVO;
  46.    };
  47.  
  48. struct     hook  owhook =
  49.    {
  50.    0,
  51.    (PFL)MyOpenWindow,
  52.    (PFL)OWentry_point,
  53.    -204
  54.    };
  55.  
  56. struct     hook  cwhook =
  57.    {
  58.    0,
  59.    (PFL)MyCloseWindow,
  60.    (PFL)CWentry_point,
  61.    -72
  62.    };
  63.  
  64. struct     hook  mihook =
  65.    {
  66.    0,
  67.    NULL,
  68.    (PFL)MIentry_point,
  69.    -150
  70.    };
  71.  
  72. struct     hook  pmhook =
  73.    {
  74.    0,
  75.    (PFL)MyPutMsg,
  76.    (PFL)PMentry_point,
  77.    -366
  78.    };
  79.  
  80. VOID
  81. SetHooks()
  82. {
  83.    Forbid();
  84.    owhook.hk_SysFunc = SetFunction(IntuitionBase,owhook.hk_LVO,owhook.hk_Entry);
  85.    cwhook.hk_SysFunc = SetFunction(IntuitionBase,cwhook.hk_LVO,cwhook.hk_Entry);
  86.    mihook.hk_SysFunc = SetFunction(IntuitionBase,mihook.hk_LVO,mihook.hk_Entry);
  87.    pmhook.hk_SysFunc = SetFunction(SysBase,pmhook.hk_LVO,pmhook.hk_Entry);
  88.    Permit();
  89. }
  90.  
  91. VOID
  92. CleanHooks()
  93. {
  94.    SetFunction(IntuitionBase,owhook.hk_LVO,owhook.hk_SysFunc);
  95.    SetFunction(IntuitionBase,cwhook.hk_LVO,cwhook.hk_SysFunc);
  96.    SetFunction(IntuitionBase,mihook.hk_LVO,mihook.hk_SysFunc);
  97.    SetFunction(SysBase,pmhook.hk_LVO,pmhook.hk_SysFunc);
  98. }
  99.  
  100.